<?php

namespace App\Http\ViewComposer;

use Illuminate\Contracts\View\View;
use App\Repositories\MenuRepository;
use App\Services\PHPTree;

class CommonComposer
{
    protected $menu;

    /**
     * Create a new menu composer.
     *
     * @param  MenuRepository  $users
     * @return void
     */
    public function __construct(MenuRepository $menu)
    {
        $this->menu = $menu;
    }

    /**
     * Bind data to the view.
     *
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    { 
        if (auth()->check()) {
            
            // 栏目缓存10分钟
            $menu = (new PHPTree($this->menu->getMenuAuth()))->render();

            $view->with('menu', $menu);
            $view->with('user', request()->user());  
        }
    }
}